| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | List of all members
nkExport::TreeReader Class Referencefinal

Utility class providing an easier way to parse trees. More...

## Public Member Functions
| TreeReader () noexcept
| TreeReader (const TreeReader &)=delete
| TreeReader (TreeReader &&other) noexcept
void | addBool (bool &target, nkMemory::StringView path)
void | addInt (int &target, nkMemory::StringView path)
void | addUint (unsigned int &target, nkMemory::StringView path)
void | addFloat (float &target, nkMemory::StringView path)
void | addString (nkMemory::String &target, nkMemory::StringView path)
template<typename T >
void | addVector (nkMemory::BufferCast< T > &target, std::function< T(nkExport::Node *)> entryFiller, nkMemory::StringView path)
template<typename T >
void | addVector (std::vector< T > &target, std::function< T(nkExport::Node *)> entryFiller, nkMemory::StringView path)
template<typename T = std::string>
void | addString (std::string &target, nkMemory::StringView path)
void | fill (nkExport::Node *tree)
TreeReader & | operator= (const TreeReader &)=delete
TreeReader & | operator= (TreeReader &&) noexcept

## Detailed Description

Utility class providing an easier way to parse trees.

The typical use when directly working on a node can look like :

nkExport::Node* child = parent->getMemberValue("a.result") ;
if (child && child->isValueTypeNumber())
target = child->getValueAsInt() ;
nkExport::Node* secondChild = ...
...

Using this utility, the code can be simplified to :

nkExport::TreeReader reader ;
reader.addInt(target, "a.result") ;
reader.addString(secondTarget, "a.reason") ;
reader.fill(parent) ;

Note that like for a Node, the path can directly index objects and arrays.

## Constructor & Destructor Documentation

## ◆ TreeReader() [1/3]

nkExport::TreeReader::TreeReader | ( |  | ) |
| noexcept

Default constructor.

## ◆ TreeReader() [2/3]

nkExport::TreeReader::TreeReader | ( | const TreeReader & |  | ) |
| delete

Copy constructor.

## ◆ TreeReader() [3/3]

nkExport::TreeReader::TreeReader | ( | TreeReader && | other | ) |
| noexcept

Move constructor.

Parameters

  other | The other instance to move from.

## Member Function Documentation

## ◆ addBool()

void nkExport::TreeReader::addBool | ( | bool & | target,
|  | nkMemory::StringView | path
| ) |  |

Adds an boolean as a target.

Parameters

  target | The target boolean to fill.
  path | The member path in the tree.

Remarks
  The member path needs to point to a boolean.

## ◆ addInt()

void nkExport::TreeReader::addInt | ( | int & | target,
|  | nkMemory::StringView | path
| ) |  |

Adds an int as a target.

Parameters

  target | The target int to fill.
  path | The member path in the tree.

Remarks
  The member path needs to point to a number.

## ◆ addUint()

void nkExport::TreeReader::addUint | ( | unsigned int & | target,
|  | nkMemory::StringView | path
| ) |  |

Adds an unsigned int as a target.

Parameters

  target | The target unsigned int to fill.
  path | The member path in the tree.

Remarks
  The member path needs to point to a number.

## ◆ addFloat()

void nkExport::TreeReader::addFloat | ( | float & | target,
|  | nkMemory::StringView | path
| ) |  |

Adds a float as a target.

Parameters

  target | The target float to fill.
  path | The member path in the tree.

Remarks
  The member path needs to point to a number.

## ◆ addString() [1/2]

void nkExport::TreeReader::addString | ( | nkMemory::String & | target,
|  | nkMemory::StringView | path
| ) |  |

Adds a string as a target.

Parameters

  target | The target string to fill.
  path | The member path in the tree.

Remarks
  The member path needs to point to a string.

## ◆ addVector() [1/2]

template<typename T >

void nkExport::TreeReader::addVector | ( | nkMemory::BufferCast< T > & | target,
|  | std::function< T(nkExport::Node *)> | entryFiller,
|  | nkMemory::StringView | path
| ) |  |

Adds a vector as target. The provided buffer will be filled one entry at a time from given member path.

Parameters

  target | The target buffer to fill.
  entryFiller | The callback used to populate the entries which need to be filled.
  path | The member path in the tree.

Remarks
  The member path needs to point to an array. For each entry available in the member array, the callback will be called to create and set it up, before appending it in the buffer.

## ◆ addVector() [2/2]

template<typename T >

void nkExport::TreeReader::addVector | ( | std::vector< T > & | target,
|  | std::function< T(nkExport::Node *)> | entryFiller,
|  | nkMemory::StringView | path
| ) |  |

Adds a vector as target, std template version. The provided vector will be filled one entry at a time from given member path.

Parameters

  target | The target vector to fill.
  entryFiller | The callback used to populate the entries which need to be filled.
  path | The member path in the tree.

Remarks
  The member path needs to point to an array. For each entry available in the member array, the callback will be called to create and set it up, before appending it in the vector.

## ◆ addString() [2/2]

template<typename T = std::string>

void nkExport::TreeReader::addString | ( | std::string & | target,
|  | nkMemory::StringView | path
| ) |  |

Adds a string as a target, std template version.

Parameters

  target | The target string to fill.
  path | The member path in the tree.

Remarks
  The member path needs to point to a string.

## ◆ fill()

void nkExport::TreeReader::fill | ( | nkExport::Node * | tree | ) |

Fills the set targets using the provided tree.

Parameters

  tree | The tree to fill the targets from.

## ◆ operator=() [1/2]

TreeReader& nkExport::TreeReader::operator= | ( | const TreeReader & |  | ) |
| delete

Copy assignment operator.

## ◆ operator=() [2/2]

TreeReader& nkExport::TreeReader::operator= | ( | TreeReader && |  | ) |
| noexcept

Move assignment operator.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsExport/Tree/Utils/TreeReader.h